<?php

    include 'sessionvalid.php';
    
    
    $username = "pocketgames_dk";
    $password = "mHiRL4bV";
    $hostname = "pocketgames.dk.mysql";
    
    
    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
    
    //select a database to work with
    $selected = mysql_select_db("pocketgames_dk",$dbhandle) or die("Could not select database");



    $result = mysql_query("SELECT id, question, answer FROM Quiz ORDER BY id");
    
    
    //fetch tha data from the database
    while ($row = mysql_fetch_array($result)) {
        echo "<form action='UpdateQuestion.php' method='post'>";
        echo "<textarea name='question' rows='5' cols='40'>";
        echo $row{'question'};
        echo "</textarea>";
        echo "<textarea name='answer' rows='5' cols='40'>";
        echo $row{'answer'};
        echo "</textarea>";
        echo "<input type='hidden' name='id' value='".$row{'id'}."'>";
        echo "<br><input type='submit' value='update'></form>";
        
        echo "<form action='DeleteQuestion.php?' method='post'>";
        echo "<input type='hidden' name='id' value='".$row{'id'}."'>";
        echo "<input type='submit' value='delete'></form>";
    }
    
    mysql_close($dbhandle);
    
    echo "<form action='CreateQuestion.php' method='post'>";
    echo "Add:<br>";
    echo "<textarea name='category' rows='5' cols='40'></textarea>";
    echo "<textarea name='answer' rows='5' cols='40'></textarea>";
    echo "<input type='submit' value='add'>";
    echo "</form>";
    
    
    echo "<br><form action='logout.php' method='post'>";
    echo "<input type='submit' value='log out'></form>";

?>